#!/bin/bash
construct_path=$(cd `dirname $0`; pwd)
keepalive_path=`cd ../ && pwd`

cp -r $keepalive_path/keepalived /usr/local

# 拷贝kp服务，并赋值相关权限。
\cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
\cp /usr/local/keepalived/etc/init.d/keepalived /etc/init.d/
\cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

chmod -R 777 /etc/init.d/keepalived
chmod -R 777 /usr/sbin/keepalived


# 设置日志单独存放于/var/log/keepalived.log
sed -i "s/KEEPALIVED_OPTIONS=\"-D\"/KEEPALIVED_OPTIONS=\"-D -d -S 0\"/g" /etc/sysconfig/keepalived
echo "local0.*   /var/log/keepalived.log"  >> /etc/rsyslog.conf
systemctl restart rsyslog

# 拷贝缺少的系统库
\cp /usr/local/keepalived/etc/lib64/libcrypto.so.1.1 /usr/lib64/
\cp /usr/local/keepalived/etc/lib64/libnl.so.1 /usr/lib64/
\cp /usr/local/keepalived/etc/lib64/libssl.so.1.1 /usr/lib64/

systemctl daemon-reload

# 增加开机自启动
chkconfig --add keepalived
chkconfig keepalived on

#临时关闭SELINUX，否则无法让keepalived执行切换脚本
setenforce 0

# 关闭firewalld的服务自启动
systemctl disable firewalld.service